package yuejian_07.yuejian_07.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import java.util.List;

import yuejian_07.yuejian_07.R;
import yuejian_07.yuejian_07.adapter.MyActOrderListAdapter;
import yuejian_07.yuejian_07.javabean.EnterActBean;
import yuejian_07.yuejian_07.model.UserModel;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MyActOrderListActivity extends AppCompatActivity {
    private ImageView left;
    private int u_id;
    private RecyclerView recyclerView;
    private Button activityOrder_button,trainOrder_button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_act_order_list);
        initViews();//初始化
        initData();//点击事件处理
        initEvent();
    }
    private void initViews() {
        recyclerView = (RecyclerView) findViewById(R.id.my_order);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));//设置布局

        left = (ImageView) findViewById(R.id.left);
        activityOrder_button= (Button) findViewById(R.id.act_order);
        trainOrder_button= (Button) findViewById(R.id.train_order);
    }
    private void initEvent() {
        //返回上一页
        left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });


        trainOrder_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent =new  Intent(MyActOrderListActivity.this,MyTrainOrderListActivity.class);
                startActivity(intent);
            }
        });

    }

    private void initData() {
        SharedPreferences sp = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        u_id = sp.getInt("user_id", 0);
            Log.d("we","u_id");

        UserModel userModel = new UserModel();
        //发送请求
        Call<List<EnterActBean>> call = userModel.getMyActOrderlist
                (u_id);
        //2.处理结果
        call.enqueue(new Callback<List<EnterActBean>>() {
            @Override
            public void onResponse(Call<List<EnterActBean>> call, Response<List<EnterActBean>> response) {
                List<EnterActBean> data = (List<EnterActBean>) response.body();  //获取数据
                recyclerView.setAdapter(new MyActOrderListAdapter(MyActOrderListActivity.this, data));
            }

            @Override
            public void onFailure(Call<List<EnterActBean>> call, Throwable t) {

            }

        });

    }
}



